using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace Hermes.Framework.Implementation
{
    public class TxDirectoryDelete : TxOperationTemplate, ITransactableDelete
    {
        public TxDirectoryDelete(string source)
            : base(source)
        {

        }

        public void Delete()
        {
            base.Execute(base.dstFileName);
        }

        protected override void Operate()
        {
            if (!this.fileSystem.IsDirectory(this.dstFileName))
            {
                throw new FileNotFoundException(this.dstFileName);
            }
            this.fileSystem.RenameDirectory(this.dstFileName, this.shadowFileName);
        }

        public override void Commit()
        {
            this.fileSystem.RemoveDirectory(base.dstFileName);
        }

        public override void Rollback()
        {
            this.fileSystem.RenameDirectory(this.shadowFileName, this.dstFileName);
        }
    }
}
